﻿<inter:PluginConfigForm x:Class="Convertor.Plugin.Filter.ConfigForm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:inter="clr-namespace:Convertor.Interface;assembly=Convertor.Interface"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sm="clr-namespace:Wpf.CommonTools.SystemExtension;assembly=Wpf.CommonTools"
             xmlns:conv="clr-namespace:Wpf.CommonTools.Converter;assembly=Wpf.CommonTools"
             xmlns:local="clr-namespace:Convertor.Plugin.Filter"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:regex="clr-namespace:System.Text.RegularExpressions;assembly=System"
             mc:Ignorable="d" 
             d:DesignWidth="500" Loaded="UserControl_Loaded_1">
    <inter:PluginConfigForm.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Convertor;component\Assets\Style.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.zh.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.en.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <conv:EnumHasFlagMultiConverter x:Key="EnumHasFlagMultiConverter"/>
            <conv:EnumToVsibleConverter x:Key="EnumToVsibleConverter"/>
            <conv:EnumToCollapsedConverter x:Key="EnumToCollapsedConverter"/>
            <conv:FindUILanguageConverter x:Key="FindUILanguageConverter"/>

            <ObjectDataProvider x:Key="ReturnTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:ReturnTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="ReplaceTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:ReplaceTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="RegexOptions" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="regex:RegexOptions"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </ResourceDictionary>
    </inter:PluginConfigForm.Resources>
    <DockPanel MinWidth="500" MaxWidth="800" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config}">
        <AdornerDecorator DockPanel.Dock="Top">
            <ComboBox Name="cbReturnType"
                      ItemsSource="{Binding Source={StaticResource ReturnTypes}}"
                      SelectedItem="{Binding Path=ReturnType}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_Filter_ReturnTypes_'}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_Filter_ReturnTypes}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </ComboBox>
        </AdornerDecorator>
        <AdornerDecorator DockPanel.Dock="Top">
            <TextBox x:Name="tbFilter" ToolTip="Filter" AcceptsReturn="True" AcceptsTab="True"
                     Text="{Binding Path=FilterText, UpdateSourceTrigger=PropertyChanged}"
                     MouseDoubleClick="tbFilter_MouseDoubleClick_1">
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_Filter_RegexText}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </TextBox>
        </AdornerDecorator>

        <DockPanel DockPanel.Dock="Top"          
                   Visibility="{Binding ElementName=cbReturnType, Path=SelectedItem, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:ReturnTypes.Replace}}">
            <AdornerDecorator DockPanel.Dock="Top">
                <ComboBox Name="cbReplaceType"
                      ItemsSource="{Binding Source={StaticResource ReplaceTypes}}"
                      SelectedItem="{Binding Path=ReplaceType}" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_Filter_ReplaceTypes_'}"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_Filter_ReplaceTypes}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </ComboBox>
            </AdornerDecorator>

            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox x:Name="tbReplace"
                         Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config.ReplaceText, UpdateSourceTrigger=PropertyChanged}"
                         Visibility="{Binding ElementName=cbReplaceType, Path=SelectedItem, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:ReplaceTypes.CustomText}}"
                         MouseDoubleClick="tbFilter_MouseDoubleClick_1" ToolTip="Filter" AcceptsReturn="True" AcceptsTab="True">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_Filter_ReplaceText}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <!--<AdornerDecorator DockPanel.Dock="Top">
                <TextBox x:Name="tbMemoryAddress"
                         Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config.MemoryAddress, UpdateSourceTrigger=PropertyChanged}"
                         Visibility="{Binding ElementName=cbReplaceType, Path=SelectedItem, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:ReplaceTypes.Memory}}"
                         MouseDoubleClick="tbFilter_MouseDoubleClick_1" ToolTip="Filter" AcceptsReturn="True" AcceptsTab="True">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_Filter_MemoryAddressText}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>-->
        </DockPanel>
        <AdornerDecorator DockPanel.Dock="Top">
            <ListBox Name="lsbRegexOptions" ItemsSource="{Binding Source={StaticResource RegexOptions}}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Path=.}" Tag="{Binding Path=.}" 
                                      Visibility="{Binding Path=., Converter={StaticResource EnumToCollapsedConverter}, ConverterParameter={x:Static regex:RegexOptions.None}}"
                                      Checked="CheckBox_Checked_1"
                                      Unchecked="CheckBox_Unchecked_1">
                            <CheckBox.IsChecked>
                                <MultiBinding Converter="{StaticResource EnumHasFlagMultiConverter}" Mode="OneWay">
                                    <Binding Path="Config.RegexOption" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}"/>
                                    <Binding Path="."/>
                                </MultiBinding>
                            </CheckBox.IsChecked>
                        </CheckBox>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <sm:WatermarkService.Titlemark>
                    <TextBlock Text="{DynamicResource Plugin_Filter_RegexOptions}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                </sm:WatermarkService.Titlemark>
            </ListBox>
        </AdornerDecorator>
        <TextBlock Style="{StaticResource InfoStyle}" DockPanel.Dock="Top" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config.ToolTip}"/>
    </DockPanel>
</inter:PluginConfigForm>
